using UnityEngine;
using System.Collections;

public class BulletBehaviours : MonoBehaviour 
{
	
	private bool isReady;
	private float i = 1;
	public Renderer alpha;


	void Update () 
	{
        if(alpha)
		renderer.material.color = new Color(renderer.material.color.r,renderer.material.color.g,renderer.material.color.b,alpha.material.color.a);
		
		if(isReady)
		{
			i -= 1.5f *Time.deltaTime;
			renderer.material.color = new Color(renderer.material.color.r,renderer.material.color.g,renderer.material.color.b,i);
			
			if(i <= 0)
			{
				Destroy(gameObject);
			}
		}
		else
		transform.Translate(3*(Vector3.right*Time.deltaTime));

	}
	
	void OnTriggerEnter (Collider other) 
	{
		if(other.gameObject.layer == 8)
		{
			Destroy(gameObject.GetComponent<SphereCollider>());

            if (alpha)
			if(alpha.material.color.a > 0.6)
			isReady = true;
			
			else 
			Destroy(gameObject);
		}
	}
}
